// 在你的Vue组件中
<template>
  <div ref="pieChart" style="width: 100%; height: 100%; padding: 20px"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  name: "PieChart",
  methods: {
    // 接收父组件传过来的参数
    acceptParams(params) {
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(this.$refs.pieChart);
      let data = [
        { value: params.maleElderlyCount, name: "男士" },
        { value: params.femaleElderlyCount, name: "女士" }
      ];
      // 指定图表的配置项和数据
      let option = {
        title: {
          text: "男士 / 女士 入住占比",
          left: "center"
        },
        tooltip: {
          trigger: "item"
        },
        legend: {
          orient: "vertical",
          left: "left"
        },
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: "50%",
            data: data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
              }
            }
          }
        ]
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    }
  }
};
</script>
